import asyncio
from util import delay, async_timed

async def main():
    IS_TIMEOUT = 1
    if IS_TIMEOUT:
        timeout = 1.0
    else:
        timeout = 2.01

    @async_timed()
    async def main_task():
        return await delay(2, 'main_delay', interval=0.2)
    
    delay_task = asyncio.create_task(main_task())
    try:
        result = await asyncio.wait_for(asyncio.shield(delay_task), timeout=timeout)
        print('wait_for result:', result)
        result = await delay_task
        print('await result:', result)
    except asyncio.exceptions.TimeoutError:
        print('Warning: Got a timeout!')
        print(f'Was the task cancelled? {delay_task.cancelled()}')
        result = await delay_task
        print('await result:', result)
    
if '__main__' == __name__:
        
    asyncio.run(main())
            